package com.ems.service.impl;

import com.ems.entity.BatteryTempEntity;
import com.ems.mapper.BatteryTempMapper;
import com.ems.service.IBatteryTempService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ems.util.SnowflakeIdWorker;
import com.ems.util.StateEnum;
import com.ems.util.StateException;
import com.ems.vo.BatteryTempVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 电池电感温度 服务实现类
 * </p>
 * @author WuZH
 * @since 2024-04-23
 */
@Service
public class BatteryTempServiceImpl extends ServiceImpl<BatteryTempMapper, BatteryTempEntity> implements IBatteryTempService {

    @Resource
    private BatteryTempMapper batteryTempMapper;

    @Override
    public BatteryTempVo saveSingle (BatteryTempVo batteryTempVo) {
        if ( batteryTempVo == null ) {
            throw new StateException ( StateEnum.REQUEST_PARAM_EXCE );
        }
        BatteryTempEntity batteryTempEntity = new BatteryTempEntity ();
        BeanUtils.copyProperties ( batteryTempVo, batteryTempEntity );
        batteryTempEntity.setId ( SnowflakeIdWorker.getInstance ().nextStringId () );
        batteryTempEntity.setCreateTime ( new Date () );
        int insert = baseMapper.insert ( batteryTempEntity );
        if ( insert == 0 ) {
            throw new StateException ( StateEnum.INSERT_EXCE );
        }
        return batteryTempVo;
    }

    @Override
    public List<BatteryTempVo> queryList (BatteryTempVo batteryTempVo) {
        if ( batteryTempVo == null ) {
            throw new StateException ( StateEnum.REQUEST_PARAM_EXCE );
        }
        List<BatteryTempVo> batteryTempVos = batteryTempMapper.queryList ( batteryTempVo );
        return batteryTempVos;
    }

    @Override
    public Integer queryCount (BatteryTempVo batteryTempVo) {
        if ( batteryTempVo == null ) {
            throw new StateException ( StateEnum.REQUEST_PARAM_EXCE );
        }
        Integer count = batteryTempMapper.queryCount ( batteryTempVo );
        return count;
    }
}
